//
//  ClientListener.swift
//  uwantgoeasy
//
//  Created by 冯传宝 on 12/11/15.
//  Copyright © 2015 uwantsoft. All rights reserved.
//

import Foundation

public class ClientListener {
    private var goEasy: GoEasy?
    
    public init(){
        
    }
    convenience public init(goEasy:GoEasy){
        self.init()
        self.goEasy = goEasy
    }
    
    final func onAuthorizeResult(authorizeResult: AuthorizeResult){
        let resultCode = authorizeResult._resultCode
        switch resultCode{
        case MessageCode.OK.rawValue:
            print("authorize ok")
            goEasy!.connectSuccess(authorizeResult)
            onConnected()
        case MessageCode.UNAUTHORIZED.rawValue:
            print("Unauthorized")
            goEasy!.connectFailed(authorizeResult)
            onConnectFailed(GoEasyError(code: 401,content: "Unauthorized"))
        case MessageCode.INTERNAL_ERROR.rawValue:
            print("Internal server error")
            onConnectFailed(GoEasyError(code: 500,content: "Server internal error"))
        default:
            print("Unknow result:\(resultCode)")
        }
    }
    
    public func onConnected(){
        print("client on connected...")
    }
    
    public func onDisconnected(){
        print("client on disconnected...")
    }
    
    public func onConnectFailed(error: GoEasyError){
        print("client connect failed: \(error)")
    }
    
    final func goEasy(goEasy: GoEasy) {
        self.goEasy = goEasy;
    }
}